#include "head.h"

int main(int argc, char const *argv[])
{
    if (1 == argc)
    {
        printf("格式错误 : %s file_dest file_1 file_2   \n",argv[0]);
    }
    //文件数量 argc-1
    int fd_dest = open(argv[1],O_RDWR | O_CREAT | O_TRUNC , 0666 );//打开文件
   //OPEN_ERR(fd_dest);//错误判断
    lseek(fd_dest , 0 ,SEEK_SET); // 移动光标
    int fd_src = -1 ;
    int byte = 0;
    char buf[1024];
    for (size_t i = 2; i < argc; i++)
    {
        fd_src = open(argv[i],O_RDONLY);//打开文件
        //OPEN_ERR(fd_src);//错误判断
        lseek(fd_src , 0 , SEEK_SET); // 移动光标
        memset(buf,0 , sizeof(buf));
        while ((byte = read(fd_src , buf , sizeof(buf))) > 0)
        {
            write(fd_dest ,buf ,byte);
        }
        close(fd_src); //关闭文件
    }
    close(fd_dest);   //关闭文件
    return 0;
}

